--POUR CONTROLE


define erp='erp_mli2.';
define outils='outils_mli2.';



--CREATE TABLE se_par_service AS (SELECT * FROM &erp.par_service WHERE 1=2);



DELETE FROM  se_par_service ;




INSERT INTO se_par_service
 (SELECT SubStr(s.id,1,3) service_cod,
         0 enreg_id,
         'N' enreg_s,
         libelle service_lib,
         NULL service_lib2
    FROM UV_PSERVICES_EMETTEUR s
  );


 UPDATE se_par_service tf
 SET enreg_id = (select enreg_id FROM &erp.par_service f WHERE f.service_cod=tf.service_cod ) ;

 UPDATE se_art_unite SET enreg_id=&outils.enreg_id.NEXTVAL WHERE enreg_id IS NULL OR enreg_id =0;


 CALL uvse_synchroverserp('service_cod','PAR_SERVICE','O') ;

COMMIT;


SELECT &outils.stragg(source) source,service_cod, enreg_id, enreg_s, service_lib, service_lib2
FROM (
  SELECT 'uv' source ,g.* FROM se_par_service g
  UNION ALL
  SELECT 'se' source ,g.* FROM &erp.par_service g
  )
GROUP BY service_cod, enreg_id, enreg_s, service_lib, service_lib2
HAVING Count(1)!=2
ORDER BY service_cod;